package de.preisrobot.entity;

import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.Table;

 

@Entity
 @Table(name = "tree")
 public class Node {
  
     @Id
     @GeneratedValue(strategy=GenerationType.AUTO)
     private Integer id;
  
    
     private String name;
  
     @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
     @OrderColumn(name="order",updatable=true)
     @JoinColumn(name = "parent_id")
     private List<Node> children = new LinkedList<Node>();
      
     @ManyToOne(cascade= CascadeType.PERSIST  )
     @JoinColumn(name = "parent_id",insertable=false,updatable=true)
     private Node parent;

     
   public Integer getId()
   {
      return id;
   }

   public void setId(Integer id)
   {
      this.id = id;
   }

   public String getName()
   {
      return name;
   }

   public void setName(String name)
   {
      this.name = name;
   }

   public List<Node> getChildren()
   {
      return children;
   }

   public void setChildren(List<Node> children)
   {
      this.children = children;
   }

   public Node getParent()
   {
      return parent;
   }

   public void setParent(Node parent)
   {
      this.parent = parent;
   }
  
}